class Solution {
public:
    int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2)
    {
        ranges::sort(nums1);
        ranges::sort(nums2);
        int m = nums1.size(), n = nums2.size();
        int val = INT_MAX;
        function<int(vector<int>)> issame = [&](vector<int> a) {
            int x = nums2[0] - a[0];
            for (int i = 0; i < n; i++) a[i] += x;
            if (a == nums2)
                return x;
            return INT_MAX;
            };
        for (int i = 0; i < m - 1; i++)
        {
            for (int j = i + 1; j < m; j++)
            {
                vector<int> cmp(nums1);
                cmp.erase(cmp.begin() + i);
                cmp.erase(cmp.begin() + j - 1);
                val = min(val, issame(cmp));
            }
        }
        return val;
    }
};